/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.collection.CollUtil
 *  cn.hutool.core.date.DateUtil
 *  org.springframework.beans.BeanUtils
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.stereotype.Service
 *  org.springframework.transaction.annotation.Transactional
 */
package com.gys.spliteService.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.gys.mapper.GaiaSdRemoteAuditDMapper;
import com.gys.mapper.GaiaSdRemoteAuditHMapper;
import com.gys.mapper.entity.GaiaSdRemoteAuditD;
import com.gys.mapper.entity.GaiaSdRemoteAuditH;
import com.gys.spliteService.RemoteAuditService;
import com.gys.spliteService.data.GetLoginOutData;
import com.gys.spliteService.data.RemoteAuditDInData;
import com.gys.spliteService.data.RemoteAuditHInData;
import java.util.Date;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RemoteAuditServiceImpl
implements RemoteAuditService {
    @Autowired
    private GaiaSdRemoteAuditHMapper gaiaSdRemoteAuditHMapper;
    @Autowired
    private GaiaSdRemoteAuditDMapper gaiaSdRemoteAuditDMapper;

    @Override
    @Transactional
    public void insertRemoteAudit(RemoteAuditHInData inData, GetLoginOutData userInfo) {
        String client = userInfo.getClient();
        GaiaSdRemoteAuditH gaiaSdRemoteAuditH = new GaiaSdRemoteAuditH();
        BeanUtils.copyProperties(inData, gaiaSdRemoteAuditH);
        String codePre = DateUtil.format((Date)new Date(), (String)"yyMMdd");
        String voucherId = this.gaiaSdRemoteAuditHMapper.selectNextVoucherId(client, codePre);
        gaiaSdRemoteAuditH.setClientId(client);
        gaiaSdRemoteAuditH.setGsrahVoucherId(voucherId);
        gaiaSdRemoteAuditH.setGsrahBrId(userInfo.getDepId());
        gaiaSdRemoteAuditH.setGsrahBrName(userInfo.getDepName());
        gaiaSdRemoteAuditH.setGsrahUploadEmp(userInfo.getUserId());
        gaiaSdRemoteAuditH.setGsrahUploadFlag("0");
        gaiaSdRemoteAuditH.setGsrahStatus("0");
        gaiaSdRemoteAuditH.setGsrahUploadDate(DateUtil.format((Date)new Date(), (String)"yyyyMMdd"));
        gaiaSdRemoteAuditH.setGsrahUploadTime(DateUtil.format((Date)new Date(), (String)"HHmmss"));
        gaiaSdRemoteAuditH.setGsrahRecipelPicAddress(inData.getGsrahRecipelPicAddress());
        this.gaiaSdRemoteAuditHMapper.insert(gaiaSdRemoteAuditH);
        if (CollUtil.isNotEmpty(inData.getAuditDs())) {
            for (int i = 0; i < inData.getAuditDs().size(); ++i) {
                RemoteAuditDInData auditD = inData.getAuditDs().get(i);
                GaiaSdRemoteAuditD gaiaSdRemoteAuditD = new GaiaSdRemoteAuditD();
                BeanUtils.copyProperties(auditD, gaiaSdRemoteAuditD);
                gaiaSdRemoteAuditD.setClientId(client);
                gaiaSdRemoteAuditD.setGsradVoucherId(voucherId);
                gaiaSdRemoteAuditD.setGsradBrId(userInfo.getDepId());
                gaiaSdRemoteAuditD.setGsradSerial(String.valueOf(i + 1));
                this.gaiaSdRemoteAuditDMapper.insert(gaiaSdRemoteAuditD);
            }
        }
    }
}

